/*
 * List.cpp
 *
 *  Created on: Feb 20, 2011
 *      Author: akcilap
 */

#include "stack.h"
#ifdef DEBUG
#include <iostream>
#endif
void Stack::push(int val) {
#ifdef DEBUG
	std::cout << "pushing " << val << '\n';
#endif
	if(start == 0) {
		start = new node;
		start->next=start->previous = 0;
		start->val = val;
		end = start;
	} else {
		end->next = new node;
		end->next->previous = end;
		end = end->next;
		end->val = val;
		end->next = 0;
	}
	size++;
}

void Stack::pop() {
#ifdef DEBUG
	std::cout << "popping " << end->val << '\n';
#endif
	if(end != 0) {


		if(end->previous == 0) {
			delete end;
			start = end = 0;
		} else {
			end = end->previous;
			delete end->next;
			end->next = 0;
		}
		size--;
	}
}
